package com.coldchain.hz.api;


import com.coldchain.authclient.annotation.CheckUserToken;
import com.coldchain.common.feign.SystemConfigFeign;
import com.coldchain.common.msg.BaseResponse;
import com.coldchain.common.msg.ObjectRestResponse;
import com.coldchain.hz.entity.AddressSearch;
import com.coldchain.hz.entity.ReceivedAddr;
import com.coldchain.hz.service.IReceivedAddrService;
import com.fangliai.core.context.BaseContextHandler;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 冷链货主发货地址 前端控制器
 * </p>
 *
 * @author huangzm
 * @since 2018-08-29
 */
@RestController
@CheckUserToken
@RequestMapping("/hz/receivedaddr")
public class ReceivedAddrController {
	@Autowired
	private IReceivedAddrService receivedAddrService;
	@Autowired
	private SystemConfigFeign systemConfigFeign;

	/**
	 * 删除地址
	 * @param id
	 * @return
	 */
	@GetMapping("/del/{id}")
	public BaseResponse del(@PathVariable("id") Integer id){
		return receivedAddrService.del(BaseContextHandler.getCommpanyId(),id);
	}

	@GetMapping("/list")
	public BaseResponse getList(AddressSearch search){
		search.setCompanyId(BaseContextHandler.getCommpanyId());
		return new ObjectRestResponse<>().data(receivedAddrService.searchForList(search));
	}

	@GetMapping("/page")
	public BaseResponse getPage(AddressSearch search){
		search.setCompanyId(BaseContextHandler.getCommpanyId());
		return new ObjectRestResponse<>().data(receivedAddrService.search(search));
	}

	@PostMapping("/edit")
	public  BaseResponse edit(ReceivedAddr addr){
		return receivedAddrService.edit(BaseContextHandler.getCommpanyId(),addr);
	}

}
